﻿using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class hint : MonoBehaviour
{
    private Image img_Bg;
    private Text txt_Hit;

    private void Awake()
    {
        img_Bg = GetComponent<Image>();
        txt_Hit = GetComponentInChildren<Text>();
        //隐藏
        img_Bg.color = new Color(img_Bg.color.r,img_Bg.color.g, img_Bg.color.b, 0);
        txt_Hit.color = new Color(txt_Hit.color.r, txt_Hit.color.g, txt_Hit .color.b, 0);

        //监听广播 -提示信息
        EventCenter.AddListener<string>(EventDefine.Hint,Show);
    }
    private void OnDestroy()
    {
        //监听广播 -提示信息
        EventCenter.RemoveListener<string>(EventDefine.Hint, Show);
    }
    private void Show(string text) 
    {
        //拒绝多次点击-等待上一个点击结束
       StopCoroutine("Dealy");//必须使用引号“”的方式，才能将携程关闭  开启的时候也得使用引号
        transform.localPosition = new Vector3(0, -70,0);

        transform.DOLocalMoveY(0,0.3f).OnComplete(()=>
        {//结束后调用方法-开启携程
            StartCoroutine("Dealy");
        });
        img_Bg.DOColor(new Color(img_Bg.color.r,img_Bg.color.g,img_Bg.color.b,0.4f),0.1f);
        txt_Hit.DOColor(new Color(txt_Hit.color.r, txt_Hit.color.g, txt_Hit.color.b, 1), 0.1f);

    }
    private IEnumerator Dealy() 
    {
        yield return new WaitForSeconds(1f);
        transform.DOLocalMoveY(70,0.3f);
        //隐藏
        img_Bg.DOColor(new Color(img_Bg.color.r, img_Bg.color.g, img_Bg.color.b, 0), 0.1f);
        txt_Hit.DOColor(new Color(txt_Hit.color.r, txt_Hit.color.g, txt_Hit.color.b,0), 0.1f);
    }
}
